﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 战棋模拟器
{
    class 卡德加:Minion
    {
        public 卡德加():base()
        {
            Star = 3;
            Attack = 2;
            Health = 2;
        }
        //暂时只能硬编码了，因为特殊情况仅比斯巨兽一例


        public override void OnSpawn(Minion m)
        {//注意顺序，对面的比斯巨兽是不会触发的，所以不会用到这个函数，但是自己触发的需要让count归位。
            if (m.Name == "芬克恩霍尔")//敲黑板：芬克恩霍尔没有金色！！！！金的并不会招６／６
                return;
            if (pool.minionCount == 7)
                return;

            //这段正确实现了一个炉石bug
            if (m.NewOne().Skills[4])
                return;

            if (pool.board.Debug)
            {
                pool.board.Showboard();
                Console.WriteLine("{0}号卡德加的特效触发", Place);
            }
            Minion duplicate = m.Copy();
            //duplicate.Name = m.Name;
            //duplicate.Health = m.Health;
            //duplicate.Attack = m.Attack;
            //duplicate.plants = m.plants;
            //duplicate.magnet = m.magnet;
            //duplicate.pool = pool;
            //duplicate.Place = m.Place+1;
            //for (int i = 0; i <= 5; i++)
            //    duplicate.Skills[i] = m.Skills[i];
            pool.AddMinion(m.Place+1, duplicate);
            duplicate.Initialize();
            if (duplicate.Place<= pool.current)
                pool.current++;
            List<Minion> Todo = new List<Minion>();
            foreach (Minion n in pool.places)
            {
                if (n == null)
                    break;
                if (n.Name != "卡德加" && n.Name != "卡德加_金色")
                    Todo.Add(n);
            }
            foreach(Minion n in pool.places)
            {
                if (n == null)
                    break;
                if ((n.Name == "卡德加" || n.Name == "卡德加_金色") && n.Place > Place)
                    Todo.Add(n);
            }
            foreach (Minion n in Todo)
                n.OnSpawn(duplicate);
        }


        public override void OnEnemySpawn(Minion m)
        {
            if (m.Name != "芬克恩霍尔")
                return;
            if (m.pool.minionCount == 7)
                return;
            if (pool.board.Debug)
            {
                pool.board.Showboard();
                Console.WriteLine("{0}号卡德加的特效触发", Place);
            }
            Minion duplicate = m.Copy();
            duplicate.Name = m.Name;
            duplicate.pool = m.pool;
            duplicate.Place = m.Place + 1;
            duplicate.pool.AddMinion(duplicate.Place, duplicate);
            if (duplicate.Place <= duplicate.pool.current)
                duplicate.pool.current++;
            List<Minion> ToDo = new List<Minion>();
            foreach (Minion n in pool.places)
            {
                if (n == null)
                    break;
                if (n.Place > Place && (n.Name == "卡德加" || n.Name == "卡德加_金色"))
                    ToDo.Add(n);
            }
            foreach(Minion n in ToDo)
            {
                n.OnEnemySpawn(duplicate);
            }
        }


        public override Minion NewOne()
        {
            return new 卡德加();
        }
    }

    class 卡德加_金色 : 卡德加//这里核心思想就是多生成的两个对于其他卡德加类来说仅相当于一个，但对其他随从相当于两个
    {
        public 卡德加_金色() : base()
        {
            Attack *= 2;
            Health *= 2;
            count *= 2;
            buff *= 2;
        }

        public override Minion NewOne()
        {
            return new 卡德加_金色();
        }



        public override void OnSpawn(Minion m)
        {
            bool flag2 = false;
            if (m.Name == "芬克恩霍尔")
                return;
            if (pool.minionCount == 7)
                return;

            //实现bug
            if (m.NewOne().Skills[4])
                return;


            if (pool.board.Debug)
            {
                pool.board.Showboard();
                Console.WriteLine("{0}号卡德加_金色的特效触发", Place);
            }
            Minion duplicate = m.Copy();
            Minion duplicate1 = m.Copy();
            pool.AddMinion(m.Place+1, duplicate);
            if (duplicate.Place <= pool.current)
                pool.current++;
            if(pool.minionCount < 7)
            {
                flag2 = true;
                pool.AddMinion(m.Place+1, duplicate1);
                if (duplicate1.Place <= pool.current)
                    pool.current++;
            }
            List<Minion> Todo = new List<Minion>();
            foreach (Minion n in pool.places)
            {
                if (n == null)
                    break;
                if (n.Name != "卡德加" && n.Name != "卡德加_金色")
                    Todo.Add(n);
            }
            if (flag2)
                foreach (Minion n in Todo)
                    n.OnSpawn(duplicate1);
            foreach (Minion n in pool.places)
            {
                if (n == null)
                    break;
                if ((n.Name == "卡德加" || n.Name == "卡德加_金色") && n.Place > Place)
                    Todo.Add(n);
            }
            foreach (Minion n in Todo)
                n.OnSpawn(duplicate);
        }



        public override void OnEnemySpawn(Minion m)
        {
            if (m.Name != "芬克恩霍尔")
                return;
            if (m.pool.minionCount == 7)
                return;
            if (pool.board.Debug)
            {
                pool.board.Showboard();
                Console.WriteLine("{0}号卡德加_金色的特效触发", Place);
            }
            Minion duplicate = m.NewOne();
            Minion duplicate1 = m.NewOne();
            pool.next.AddMinion(m.Place+1, duplicate);
            if (duplicate.Place <= duplicate.pool.current)
                duplicate.pool.current++;
            if (m.pool.minionCount < 7)
            {
                pool.next.AddMinion(m.Place+1, duplicate1);
                if (duplicate1.Place <= duplicate1.pool.current)
                    duplicate1.pool.current++;
            }
            List<Minion> ToDo = new List<Minion>();
            foreach (Minion n in pool.places)
            {
                if (n == null)
                    break;
                if (n.Place > Place && (n.Name == "卡德加" || n.Name == "卡德加_金色"))
                    ToDo.Add(n);
            }
            foreach (Minion n in ToDo)
            {
                n.OnEnemySpawn(duplicate);
            }
        }
    }
}
